home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
gr_col.exe
/
GR_COL2G.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-04-17
|
13KB
|
338 lines
{ == GR_COL2F.PAS =============================================================
Test writeln in color within graphics. Shows that you CAN write color text
in graphics, with the correct background!
The "background" cannot be set via TextBackground, but must be drawn with
graphics, such as Bar
This program demonstrates all 16 VGA text colors against the 16 VGA colors
as graphics backgrounds. It shows the background RGB "combined value" (see
below), the foreground RGB "combined value", and the resulting XOR combined
value.
The XorColConv procedure calculates the correct VGA color number ( Black:0
to White:15) which results when a background and foreground color are XOR'd.
Diagnostic prints within the procedure show the values being manipulated.
If the background and foreground colors COR to a "standard" 16-color VGA
combined value, TRUE is shown, while FALSE is shown if the "exception"
look-up table has been used to find the output VGA color.
Take a look at the procedure code and comments to tell you what's happening.
Written by Jerry Rivers. Last modified: 04/16/93
============================================================================= }
PROGRAM Gr_Color;
uses Graph, Crt, DosUtil;
const
ColNam : array[0..15] of string[12] = (
'Black', 'Blue', 'Green', 'Cyan',
'Red', 'Magenta', 'Brown', 'LtGray',
'DarkGray', 'LtBlue', 'LtGreen', 'LtCyan',
'LtRed', 'LtMagenta', 'Yellow', 'White' );
var
Ch : char;
ColorBack,
ColorIn,
ColorOut : integer; { color parms for XorColConv }
Colr : text;
Driver : integer;
GRreturn : integer;
I : byte;
Mode : integer;
Txt : text;
{ == XorColConv ===============================================================
(*// Procedure: XorColConv
Purpose: Calculates color resulting from background XOR foreground in graphics
Syntax: PROCEDURE
XorColConv( ColBkGnd, ColSet : integer; var ColResult : integer );
Parameters:
ColBkGnd Input background color: VGA 0 (Black) to 15 (White)
ColSet Input foreground color: VGA 0-15
ColResult Output resulting VGA color of ColSet XOR on ColBkGnd
Remarks: RGB colors in decimal for the 16 "standard" VGA colors
These numbers are calculated by this formula:
ColorValue := ( Red * 65536 ) + ( Green * 256 ) + Blue
example, "standard" LightBlue is Red = $15, Green = $15, Blue = $3F
This "combines" to give $15153F = 1381695 decimal
The default palette is:
0; Red = $00; Green = $00; Blue = $00) Black = 0
1; Red = $00; Green = $00; Blue = $2A) Blue = 42
2; Red = $00; Green = $2A; Blue = $00) Green = 10752
3; Red = $00; Green = $2A; Blue = $2A) Cyan = 10794
4; Red = $2A; Green = $00; Blue = $00) Red = 2752512
5; Red = $2A; Green = $00; Blue = $2A) Magenta = 2752554
6; Red = $2A; Green = $15; Blue = $00) Brown = 2757888
7; Red = $2A; Green = $2A; Blue = $2A) LightGray = 2763306
8; Red = $15; Green = $15; Blue = $15) DarkGray = 1381653
9; Red = $15; Green = $15; Blue = $3F) LightBlue = 1381695
10; Red = $15; Green = $3F; Blue = $15) LightGreen = 1392405
11; Red = $15; Green = $3F; Blue = $3F) LightCyan = 1392447
12; Red = $3F; Green = $15; Blue = $15) LightRed = 4134165
13; Red = $3F; Green = $15; Blue = $3F) LightMagenta = 4134207
14; Red = $3F; Green = $3F; Blue = $15) Yellow = 4144917
15; Red = $3F; Green = $3F; Blue = $3F) White = 4144959
This version of XorColConv also writes two text files to the current
directory: 'coltxt.txt', which is the same as the diagnostic prints
to the screen and 'col.txt' which is just the raw "exception" values
before the duplicates are removed.
Duplicates are removed and the exception tables are built by another
utility program: RECOL3.PAS
Refer
Globals: ColNam[]
Txt
Colr
Modify
Globals: None
See also:
Example:
(*
Set the input parameters
*)
ColorBack := White;
ColorIn := LightRed;
(*
Create a color graphics "background"
*)
SetFillStyle( SolidFill, ColorBack );
Bar( 0, 0, 639, 479 );
(*
Convert White to its resulting XOR output
In this case, White XOR LightRed = Cyan
Cyan is the inverse of LightRed so it creates true LightRed against
a white background when used by TextColor. the "+ 128" forces bit 7
of TextAttr "on" which causes BIOS writes in graphics to be XOR'd
unto the screen. Voila! You get LightRed text on White!
*)
XorColConv( ColorBack, ColorIn, ColorOut );
TextColor( ColorOut + 128 );
writeln( ColNam[ColorIn]:12, ColNam[ColorOut]:12 );
(*
Will print: LtRed Cyan
*)
writeln(' This should be ', ColNam[ColorIn] );
(*
Will print: This should be LtRed
*)
\\*)
Written by Jerry Rivers. Last modified: 04/16/93
============================================================================= }
PROCEDURE XorColConv( ColBkGnd, ColSet : integer; var ColResult : integer );
const
ColVal : array[0..15] of longint = (
0, 42, 10752, 10794,
2752512, 2752554, 2757888, 2763306,
1381653, 1381695, 1392405, 1392447,
4134168, 4134207, 4144917, 4144959 );
var
Color1, Color2, Color3 : longint;
I : byte;
OK : boolean;
RGB : array[1..30] of longint; { RGB exceptions }
Col : array[1..30] of integer; { corresponding colors }
begin
{
Initialize the Color exception tables - developed visually
My tests show there are 16 "exact" color matches (to standard 16-color
VGA values) plus 29 "exceptions". These exceptions result in nearly but
not quite exact visual representations of the standard colors. Exception
values can be mapped to a standard color which looks OK to the eye.
}
RGB[ 1] := 2757930; Col[ 1] := 7;
RGB[ 2] := 2763264; Col[ 2] := 6;
RGB[ 3] := 4134194; Col[ 3] := 13;
RGB[ 4] := 4134165; Col[ 4] := 12;
RGB[ 5] := 2768640; Col[ 5] := 4;
RGB[ 6] := 4144920; Col[ 6] := 14;
RGB[ 7] := 2768682; Col[ 7] := 5;
RGB[ 8] := 4144946; Col[ 8] := 15;
RGB[ 9] := 5376; Col[ 9] := 2;
RGB[10] := 1381656; Col[10] := 8;
RGB[11] := 5418; Col[11] := 3;
RGB[12] := 1381682; Col[12] := 9;
RGB[13] := 16170; Col[13] := 1;
RGB[14] := 4128789; Col[14] := 14;
RGB[15] := 4128831; Col[15] := 15;
RGB[16] := 4139541; Col[16] := 12;
RGB[17] := 4139583; Col[17] := 13;
RGB[18] := 1376280; Col[18] := 10;
RGB[19] := 1376319; Col[19] := 11;
RGB[20] := 1387029; Col[20] := 8;
RGB[21] := 1387071; Col[21] := 9;
RGB[22] := 1392434; Col[22] := 11;
RGB[23] := 2752525; Col[23] := 4;
RGB[24] := 2752551; Col[24] := 5;
RGB[25] := 2763277; Col[25] := 6;
RGB[26] := 2763303; Col[26] := 7;
RGB[27] := 39; Col[27] := 1;
RGB[28] := 10765; Col[28] := 2;
RGB[29] := 10791; Col[29] := 3;
{
Get long integer RGB color numbers for background and "desired" color
}
Color1 := ColVal[ ColBkGnd ];
Color2 := ColVal[ ColSet ];
Color3 := Color1 XOR Color2;
{
If the XOR color matches a "standard" VGA color, you're done!
}
I := 0; OK := false